import api from '../../api';

// 系统配置相关接口
export interface SystemConfig {
  siteName: string;
  siteDescription?: string;
  allowRegister: boolean;
  emailVerificationRequired: boolean;
  [key: string]: any;
}

export interface SystemInfo {
  version: string;
  buildTime: string;
  uptime: number;
  environment: string;
}

export interface SystemStats {
  totalUsers: number;
  onlineUsers: number;
  totalRequests: number;
  avgResponseTime: number;
}

// 系统设置API
export const systemApi = {
  // 获取系统配置
  getConfig: () => {
    return api.get('/system/config');
  },

  // 更新系统配置
  updateConfig: (data: any) => {
    return api.put('/system/config', data);
  },

  // 获取系统信息
  getSystemInfo: () => {
    return api.get('/system/info');
  },

  // 获取系统统计
  getSystemStats: () => {
    return api.get('/system/stats');
  },

  // 清除缓存
  clearCache: () => {
    return api.post('/system/cache/clear');
  },

  // 获取日志
  getLogs: (params?: { 
    level?: string; 
    startTime?: string; 
    endTime?: string; 
    page?: number; 
    size?: number; 
  }) => {
    return api.get('/system/logs', { params });
  },
};

// 文件上传API
export const uploadApi = {
  // 上传头像
  uploadAvatar: (file: File) => {
    const formData = new FormData();
    formData.append('file', file);
    return api.post('/upload/avatar', formData, {
      headers: {
        'Content-Type': 'multipart/form-data',
      },
    });
  },

  // 上传文件
  uploadFile: (file: File, type?: string) => {
    const formData = new FormData();
    formData.append('file', file);
    if (type) {
      formData.append('type', type);
    }
    return api.post('/upload/file', formData, {
      headers: {
        'Content-Type': 'multipart/form-data',
      },
    });
  },

  // 删除文件
  deleteFile: (url: string) => {
    return api.delete('/upload/file', { data: { url } });
  },
}; 